package com.example.javabasic.thread.classtwo.future.demo1;

import java.util.concurrent.Callable;

public class AsyncFuture<T> implements Future<T> {
    //用来判断是否结束
    private volatile boolean done = false;
    private T result ;
    //当任务完成的时候, 调用此方法,并且保存结果集
    public void done(T result){
        synchronized (this){
            this.result = result;
            this.done = true;
            this.notifyAll();
        }
    }
    //如果有个线程要获取结果时   在这里阻塞
    @Override
    public T get() throws InterruptedException {
        synchronized (this){
            while(!done){
                this.wait();
            }
        }
        return result;
    }
}
